var myCirclePlayer;
var currItemNumber;
var sermonList = [
	"../AUDIO/2010/CAMPMEETING%202010/Nichols.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Stiltner%201.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Kevin%20Noles.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Jack%20Thrift.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Rusty%20Norred.mp3",
	"../AUDIO/2010/SUNDAY%20SCHOOL/09-26-10%20SUNDAY%20SCHOOL.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Stiltner%202.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%201.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%202.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%203.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%204.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%205.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%206%20.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%207.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%208.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Carpenter%209.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Mullins%201.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Mullins%202.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Mullins%203.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Smith%201.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Smith%202.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Smith%203.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Smith%204.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Rachel%20Mullins%201.mp3",
	"../AUDIO/2010/CAMPMEETING%202010/Paul%20Russ.mp3"
];

function selectItem(item) {
    if (0 <= currItemNumber && currItemNumber < sermonList.length) {
    	var currItem = document.getElementById("player-item-" + currItemNumber.toString());
        removeClass(currItem, 'bold');
        removeClass(currItem, 'colorPrimary-5');
        addClass(currItem, 'colorSecondary-a-2');
    }
    addClass(item, 'bold');
    addClass(item, 'colorPrimary-5');
    removeClass(item, 'colorSecondary-a-2');
    currItemNumber = parseInt(item.id.substr(item.id.lastIndexOf("-") + 1));
    myCirclePlayer.setMedia({
    	mp3: sermonList[currItemNumber]
    });
}

function playItem(item) {
    selectItem(item);
	myCirclePlayer.play();
}

function playNextItem() {
    var nextItemNumber = currItemNumber + 1;
    if (nextItemNumber < sermonList.length) {
        playItem(document.getElementById("player-item-" + nextItemNumber.toString()));
    }
}

$(document).ready(function(){
	myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
	{
	}, {
		supplied: "mp3",
		cssSelectorAncestor: "#cp_container_1",
		swfPath: "../Content/Javascript/jplayer/Jplayer.swf",
		wmode: "window",
		keyEnabled: true
	});

	$("#jquery_jplayer_1").bind($.jPlayer.event.ended, function (event) {
		if (currItemNumber < 6) {
        	playNextItem();
    	}
    });

	for(var i = 0; i < sermonList.length; ++i){
		addClass(document.getElementById("player-item-" + i.toString()), 'colorSecondary-a-2');
	}

	selectItem(document.getElementById("player-item-0"));
});
